package com.kha.listone.common;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;

import com.kha.listone.ListOne;
import com.kha.listone.util.Commands;
import com.kha.listone.util.Globals;
import com.kha.listone.util.Orientation;
import com.kha.listone.util.operation.OperationsQueue;

public class SingleScreen extends Form implements CommandListener {

	protected final ListOne mainMIDlet;
	protected OperationsQueue enququeOperation;

	public SingleScreen(ListOne midlet, String title) {
		super(title);
		this.mainMIDlet = midlet;
		enququeOperation = new OperationsQueue();
		
		initScreen();
	}

	protected void initScreen() {
		Orientation.enableOrientations();
		// Option Menu Commands
		if (Globals.HAVE_DROPBOX) {
			this.addCommand(Commands.SYNC);
		}
		this.addCommand(Commands.SETTING);
		this.addCommand(Commands.ABOUT);		
		this.addCommand(Commands.BACK);
		// Option Menu Commands
		this.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if (c == Commands.BACK) {
			mainMIDlet.back();
		}

		if (c == Commands.ABOUT) {
			mainMIDlet.next(mainMIDlet.getAboutScreen());
		}

		if (c == Commands.SETTING) {
			mainMIDlet.next(mainMIDlet.getSettingScreen());
		}

		if (c == Commands.SYNC) {
			// TODO
		}

	}
	
	public void refresh(){
		
	}
	
	protected void showMessage(String title, String text, AlertType type, Image image){
		Alert alert = new Alert(title, text, image, type);
		mainMIDlet.showDisplay(alert);
	}

}
